#include <stdio.h>
#include "value.h"

int main()
{
    //数据初始化,分隔符和补零设置
    Value *b = new Value(true); 
    Value *ba = new Value(3, true, false, true);
    Value *c = new Value('R');
    Value *str = new Value((char*)"一三五七九");
    Value *stra = new Value(3, (char*)"1", (char*)"23", (char*)"456"); stra->Sep() = ',';
    Value *i = new Value(10086); i->Sep() = '%';
    Value *ia = new Value(3, 12, 34, 56); ia->Zero() = 8; ia->Sep() = '-';
    Value *d = new Value(123.123456789); d->Zero() = 10;
    Value *da = new Value(3, 12.34, 5.678, 9.0123); da->Sep() = '@';
    Value *p = new Value(d);
    Value *pa = new Value(3, d, da, i); pa->Sep() = '_';
    Value *va = new Value(4, VT_BOOL, VT_STRING, VT_DOUBLE_ARRAY, VT_INT); va->Sep() = '+';

    //value数组进一步初始化
    va->GetValueArray()[1].Reset((char*)"abcd");
    va->GetValueArray()[2].Reset(3, 1.23, 4.56, 7.89);
    va->GetValueArray()[2].Sep() = '_';
    va->GetValueArray()[3].GetInt() = 10086;

    //拷贝构造
    Value *dac = new Value(*da); dac->Sep() = '\t';
    Value *strac = new Value(*stra); strac->Sep() = '\n';
    Value *vac = new Value(*va); vac->Sep() = '=';

    printf("\r\n>>> Base test : sizeof(Value) = %ld\r\n", sizeof(Value));

    b->Print();
    ba->Print();
    c->Print();
    str->Print();
    stra->Print();
    i->Print();
    ia->Print();
    d->Print();
    da->Print();
    p->Print();
    pa->Print();
    va->Print();

    dac->Print();
    strac->Print();
    vac->Print();

    b->PrintJson();
    ba->PrintJson();
    c->PrintJson();
    str->PrintJson();
    stra->PrintJson();
    i->PrintJson();
    ia->PrintJson();
    d->PrintJson();
    da->PrintJson();
    p->PrintJson();
    pa->PrintJson();
    va->PrintJson();

    dac->PrintJson();
    strac->PrintJson();
    vac->PrintJson();

    printf("\r\n>>> ArrayAdd test\r\n");

    ba->ArrayAdd(true);
    stra->ArrayAdd((char*)"addstr");
    da->ArrayAdd(98.7654321);
    pa->ArrayAdd((void*)&ba);
    va->ArrayAdd(&va->GetValueArray()[2]);

    ba->Print();
    stra->Print();
    da->Print();
    pa->Print();
    va->Print();

    ba->PrintJson();
    stra->PrintJson();
    da->PrintJson();
    pa->PrintJson();
    va->PrintJson();

    printf("\r\n>>> ToValueArray test\r\n");

    b->ArrayAdd(123);
    ba->ArrayAdd(123);
    c->ArrayAdd(123);
    str->ArrayAdd(123);
    stra->ArrayAdd(123);
    i->ArrayAdd((char*)"123");

    // b->ToValueArray();
    // ba->ToValueArray();
    // c->ToValueArray();
    // str->ToValueArray();
    // stra->ToValueArray();
    // i->ToValueArray();
    ia->ToValueArray();
    d->ToValueArray();
    da->ToValueArray();
    p->ToValueArray();
    pa->ToValueArray();
    va->ToValueArray();

    dac->ToValueArray();
    strac->ToValueArray();
    vac->ToValueArray();

    b->PrintJson();
    ba->PrintJson();
    c->PrintJson();
    str->PrintJson();
    stra->PrintJson();
    i->PrintJson();
    ia->PrintJson();
    d->PrintJson();
    da->PrintJson();
    p->PrintJson();
    pa->PrintJson();
    va->PrintJson();

    dac->PrintJson();
    strac->PrintJson();
    vac->PrintJson();

    //内存回收
    delete b;
    delete ba;
    delete c;
    delete str;
    delete stra;
    delete i;
    delete ia;
    delete d;
    delete da;
    delete p;
    delete pa;
    delete va;

    delete dac;
    delete strac;
    delete vac;

    printf(" ----- test end ----- \r\n");
    return 0;
}
